package com.anp.business.utils;


import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.util.LinkedHashMap;
import java.util.Map;

/**
 * description of URLConnectionHeaderUtil :
 * author : CM
 * createDate : 2017/5/24 16:16
 * created by IntelliJ IDEA.
 */
public class URLConnectionHeaderUtil {

    public static Map<String, String> printResponseHeader(HttpURLConnection http) throws UnsupportedEncodingException {
        Map<String, String> header = getHttpResponseHeader(http);
        return header;
    }

    private static Map<String, String> getHttpResponseHeader(
            HttpURLConnection http) throws UnsupportedEncodingException {
        Map<String, String> header = new LinkedHashMap<String, String>();
        for (int i = 0;; i++) {
            String mine = http.getHeaderField(i);
            if (mine == null)
                break;
            header.put(http.getHeaderFieldKey(i), mine);
        }
        return header;
    }
}
